package com.leather.quan.vo;

import com.leather.common.entity.QuanComment;
import com.leather.common.result.CodeMsg;
import com.leather.common.result.Result;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Date;

@Data
public class CommentAddVo  implements Serializable {

    private Integer quanId;

    private Integer userId;

    private String content;


    public Result validate(){
        if(userId<0) {
            return Result.error(CodeMsg.ERROR_USER_ID);
        }
        if(quanId<0) {
            return Result.error(CodeMsg.ERROR_QUAN_ID);
        }
        if(StringUtils.isBlank(content)) {
            return Result.error(CodeMsg.EMPTY_COMMENT_VALUE);
        }
        return  Result.success(transfer());
    }


    private QuanComment transfer(){
        QuanComment quanComment = new QuanComment();
        quanComment.setId(0);
        quanComment.setQuanId(quanId);
        quanComment.setUserId(userId);
        quanComment.setContent(content);
        quanComment.setCreateTime(new Date());
        quanComment.setFlag(0);
        return quanComment;
    }
}
